package com.jie.other.jetpack

import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.ViewGroup.LayoutParams
import android.widget.TextView
import com.jie.commonlib.base.BaseActivity
import com.jie.other.R
import com.jie.other.jetpack.observer.LifecycleStudyObserver

/**
 * lifecycle框架学习测试页面
 */
class LifecycleActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(TextView(this).apply {
            width = LayoutParams.MATCH_PARENT
            height = LayoutParams.MATCH_PARENT
            gravity = Gravity.CENTER
            text = getString(R.string.other_lifecycle)
        })

        initActionBar()
        lifecycle.addObserver(LifecycleStudyObserver())
    }

    private fun initActionBar() {
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        supportActionBar?.setTitle(R.string.other_lifecycle)
    }

    override fun onResume() {
        super.onResume()
        Log.i(TAG, "onResume: $TAG")
    }

    override fun onPause() {
        super.onPause()
        Log.i(TAG, "onPause: $TAG")
    }

    companion object{
        private const val TAG = "LifecycleActivity"
    }

}